<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>兑换券管理管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
		
		var check_val = [];
		//全选
		function selectAll(n){
			if(n.checked){
				check_val = []
				$("input[type=checkbox]").each(function(i,n) {
					if(i>0){
						this.checked = true; 
				        check_val.push(n.value)
					}
		        });  
				
			}else{
				$("input[type=checkbox]").each(function(i,n) {  
		            this.checked = false; 
		            check_val = []
		        });
			}
			$("#productId").val(check_val);
		}
		
		//单选
		function check(n){
		
			if(n.checked){
				check_val.push(n.value)
			}else{
				check_val.splice($.inArray(n.value,check_val),1)
			}
			$("#productId").val(check_val);
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/crab/coupon/">兑换券管理列表</a></li>
		<li class="active"><a href="${ctx}/crab/coupon/form?id=${coupon.id}">兑换券管理<shiro:hasPermission name="crab:coupon:edit">${not empty coupon.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="crab:coupon:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="coupon" action="${ctx}/crab/coupon/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<form:hidden path="productId"/>
		<sys:message content="${message}"/>		
		<div class="control-group">
			<label class="control-label">兑换券名称：</label>
			<div class="controls">
				<form:input path="name" htmlEscape="false" maxlength="32" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">卡号前缀：</label>
			<div class="controls">
				<form:input path="cardNumRule" htmlEscape="false" maxlength="10" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
				<span class="help-inline"><font color="red">备注：兑换券卡号规则=卡号前缀+数量升序  ,例如  卡号前缀=aa</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;数量=10 生成的卡号aa0001-aa0010  导入为卡号前缀</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">价格：</label>
			<div class="controls">
				<form:input path="price" htmlEscape="false" class="input-xlarge number required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">数量：</label>
			<div class="controls">
				<form:input path="num" htmlEscape="false" maxlength="5" class="input-xlarge digits required"/>
				<span class="help-inline"><font color="red">*</font> </span>
				<span class="help-inline"><font color="red">备注：兑换券卡号需导入 那么数量为 "0"</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">备注：</label>
			<div class="controls">
				<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="255" class="input-xxlarge "/>
			</div>
		</div>
		<div class="control-group">
			<table id="contentTable" class="table table-striped table-bordered table-condensed">
				<thead>
					<tr>
						<th><input type="checkbox" name="ck" onclick="selectAll(this)"></th>
						<th>名称</th>
						<th>图片</th>
						<th>价格</th>
						<th>库存</th>
						<th>备注</th>
					</tr>
				</thead>
				<tbody>
				<c:forEach items="${coupon.crabProduct}" var="crabProduct">
					<tr>
						<td>
							<input type="checkbox" value ="${crabProduct.id }" onclick="check(this)">
						</td>
						<td>
							${crabProduct.name}(${crabProduct.male}${not empty crabProduct.male?"&nbsp;&nbsp;":""}${crabProduct.female})
						</td>
						<td style="height:40px;width:40px">
							<img alt="" src="${crabProduct.photo}">
						</td>
						<td>
							${crabProduct.price}
						</td>
						<td>
							${crabProduct.num}
						</td>
						<td>
							${crabProduct.remarks}
						</td>
					</tr>
				</c:forEach>
				</tbody>
			</table>
		</div>	
		<div class="form-actions">
			<shiro:hasPermission name="crab:coupon:save"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>